package com.ezandroid.library.network.download;

public class DownObjectJob {

    public static final int STATE_UNKNOWN = -1;// 默认状态
    public static final int STATE_WAITING = 0;// 在下载队列，还没开始下载
    public static final int STATE_RUNNING = 1;// 开始下载，正在下载歌曲
    public static final int STATE_FINISHED = 2;// 下载完成
    public static final int STATE_FAILED = 3;// 下载失败
    public static final int STATE_PAUSE = 4;// 下载暂停

    public interface IDownObjectFinishListener {

        void onDownObjectFinished(IDownloadable downloadable, int state);
    }

    private IDownloadable mDownloadable;
    private DownFileTask mTask;

    private IDownObjectFinishListener mListener;

    private int mState = STATE_UNKNOWN;

    public DownObjectJob(IDownloadable downloadable) {
        mDownloadable = downloadable;
    }

    public void setDownloadable(IDownloadable downloadable) {
        mDownloadable = downloadable;
    }

    public IDownloadable getDownloadable() {
        return mDownloadable;
    }

    public void setDownObjectFinishListener(IDownObjectFinishListener listener) {
        mListener = listener;
    }

    public IDownObjectFinishListener getDownObjectFinishListener() {
        return mListener;
    }

    public int getState() {
        return mState;
    }

    public void setState(int state) {
        mState = state;
    }

    public DownFileTask getTask() {
        return mTask;
    }

    public void setTask(DownFileTask task) {
        mTask = task;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((mDownloadable == null) ? 0 : mDownloadable.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        DownObjectJob other = (DownObjectJob) obj;
        if (mDownloadable == null) {
            if (other.mDownloadable != null) {
                return false;
            }
        } else if (!mDownloadable.equals(other.mDownloadable)) {
            return false;
        }
        return true;
    }
}
